<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/10/22
 * Time: 10:53
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\admin\middleware;

use think\facade\Session;

class Auth
{
    /**
     * 处理中间件
     * @param $request
     * @param \Closure $next
     * @return mixed|\think\response\Redirect
     */
    public function handle($request, \Closure $next)
    {
        $getSession = Session::get(config('admin.admin_session_key'));
        if (empty($getSession) && !preg_match('/login/', strtolower($request->pathinfo()))) {
            return redirect((string)url('login/index', ['url' => base64_encode(request()->url())], false, false));
        }
        $request->admin = $getSession;
        return $next($request);
    }
}